<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
</head>

<body>
    <h1>通过jq发送post形式的ajax</h1>
    <button class="btn1">发送ajax1</button>
    <button class="btn2">发送ajax2</button>
    <script>
        // 通过jq发送get形式的ajax
        // 发送方式一
        $(".btn1").on("click", function () {
            $.post("/getdata", { myname: "hello" }, function (res) {
                console.log(res);
            })
        })

        //  发送方式二
        $(".btn2").on("click", () => {
            $.ajax({
                url:"/getdata",
                data:{
                    myname:"张三"
                },
                headers:{  // 设置请求头部内容
                    header:"val"
                },
                // headers:{'Content-Type': 'application/json'},
                method:"post",
                success(res){
                    console.log(res);
                },
                dataType:"json"
            })
        })



    </script>
</body>

</html>